#include <stdio.h>  
  //模板模式..是不是和策略模式有点像
typedef struct _Basic {  
    void* pData;  
    void (*step1)(struct _Basic* pBasic);  
    void (*step2)(struct _Basic* pBasic);  
    void (*forward)(struct _Basic* pBasic);  
	void (*reverse)(struct _Basic* pBasic);
} Basic;  

  
// 默认的process实现，调用step1和step2  
void forward_Process(Basic* pBasic) {  
    if (pBasic->step1) pBasic->step1(pBasic);  
    if (pBasic->step2) pBasic->step2(pBasic);  
}
void reverse_Process(Basic* pBasic) {  
	if (pBasic->step2) pBasic->step2(pBasic); 
    if (pBasic->step1) pBasic->step1(pBasic);  
} 
  
// 定义一个初始化Basic的函数，包括process函数指针的初始化  
void initBasic(Basic* pBasic, void (*s1)(Basic*), void (*s2)(Basic*)) {  
    pBasic->forward = forward_Process; 
	pBasic->reverse = reverse_Process;
    pBasic->step1 = s1;  
    pBasic->step2 = s2;  
}  
  
// 示例step1和step2实现  
void step1Example(Basic* pBasic) {  
    printf("Executing step1\n");  
}  
  
void step2Example(Basic* pBasic) {  
    printf("Executing step2\n"); 
}  
  
int main() {  
    Basic myBasic;  
    initBasic(&myBasic, step1Example, step2Example);  
  
    
    myBasic.forward(&myBasic); 
	printf("------\n");	
	myBasic.reverse(&myBasic); 
  
    return 0;  
}